package com.zombie.logic;

import com.zombie.Constants;
import com.zombie.logic.object.Bullet;
import com.zombie.logic.object.GameObject;
import com.zombie.logic.object.LiveObject;
import com.zombie.util.Utils;

public class Formulas {

	/** return true if bullet miss target*/
	public static boolean calcMissChance(Bullet bullet, LiveObject damaged) {
		int missChance = Constants.MAX_CHANCE-(int)(damaged.getStat().evasion*Constants.MAX_CHANCE);
		if (missChance < Utils.rnd.nextInt(Constants.MAX_CHANCE)){
			return true;
		}
		return false;
	}

	public static void calcDamage(Bullet bullet, LiveObject damaged) {
		calcDamage(bullet.damage,bullet.owner,damaged);
	}

	/** calc damage considering the stats of damaged liveobject*/
	public static void calcDamage(float dmg, GameObject damager,
			LiveObject damaged) {
		int damage = (int) (dmg - damaged.getStat().defence);
		damaged.removeHp(Math.max(damage, 1),damager);		
	}

}
